package everyday;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.time.LocalDateTime;

/**
 * @Author: wenjingyuan
 * @Date: 2023/03/17/14:47
 * @Description:
 */
public class Weather1 {
    public static void main(String[] args) {
        try{
           URL url=new URL("http://t.weather.sojson.com/api/weather/city/101210101");
            InputStreamReader isReader=new InputStreamReader(url.openStream(),"UTF-8");
            BufferedReader bufferedReader=new BufferedReader(isReader);
            String str;
            while((str=bufferedReader.readLine())!=null){
                String regex="\\p{Punct}+";
                String digit[]=str.split(regex);
                System.out.println('\n'+"城市:"+digit[22]+digit[18]);
                System.out.println('\n'+"时间:"+digit[49]+"年"+digit[50]+"月"+digit[51]+"日"+digit[53]+" "+ LocalDateTime.now());
                System.out.println('\n'+"温度:"+digit[47]+"~"+digit[45]);
                System.out.println('\n'+"天气:"+digit[67]+" "+digit[63]+digit[65]);
                System.out.println('\n'+"建议:"+digit[69]);
            }
            bufferedReader.close();
            isReader.close();
        }catch (Exception exp){
            System.out.println(exp);
        }
    }
}
